package com.lianzhihui.minitiktok.adapter;

import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.echofeng.common.ui.widget.view.LikeView;
import com.echofeng.common.ui.widget.view.jzplayer.JzvdStdTikTok;
import com.lianzhihui.minitiktok.bean.hot.VideoResponse;
import com.lianzhihui.minitiktok.widget.view.ControllerView;
import com.lianzhihui.onlyleague.R;

import java.util.List;

import cn.jzvd.JZDataSource;
import cn.jzvd.Jzvd;
import cn.jzvd.JzvdStd;

/**
 * create by libo
 * create on 2020-05-20
 * description
 */
public class VideoAdapter extends BaseQuickAdapter<VideoResponse, BaseViewHolder> {

    public VideoAdapter(List<VideoResponse> data) {
        super(R.layout.item_video);
    }

    @Override
    protected void convert(BaseViewHolder helper, VideoResponse item) {
        ControllerView mControllerView = helper.getView(R.id.mControllerView);
        mControllerView.setVideoData(item);
        LikeView mLikeView = helper.getView(R.id.mLikeView);
        mLikeView.setOnLikeListener(() -> {
            if (item.getIs_like()==1) {  //1是0否
                mControllerView.like();
            }
        });

        JzvdStdTikTok mVideoPlayer = helper.getView(R.id.videoPlayer);
//        JZDataSource jzDataSource = new JZDataSource(item.getVideoRes(),item.getContent());
//        jzDataSource.looping = true;
//        mVideoPlayer.setUp(jzDataSource, Jzvd.SCREEN_NORMAL);
//        Glide.with(mVideoPlayer.getContext()).load(item.getCoverRes()).into(mVideoPlayer.posterImageView);

        JZDataSource jzDataSource = new JZDataSource("http://ivi.bupt.edu.cn/hls/cctv1hd.m3u8","南京街坊");
        jzDataSource.looping = true;
        mVideoPlayer.setUp(jzDataSource, Jzvd.SCREEN_NORMAL);
        Glide.with(mVideoPlayer.getContext()).load(item.getCover()).into(mVideoPlayer.posterImageView);
    }
}
